package model.search;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import model.basics.ClassRoom;
import model.basics.MobileResource;
import model.search.Order;
import model.time.DailyTimeFrame;
import model.time.MonthlyTimeFrame;
import model.time.SingleTimeFrame;
import model.time.TimeFrame;
import model.time.WeeklyTimeFrame;

/**
 * This class is in charge of search for information in the data base.
 * @author Alexis 
 * */
public class Registry {
	

	
	
	/**
	 * This method returns all classroom that have an order associated
	 * @param crs
	 * @param tfs
	 * */
	public List<ClassRoom> calculateAllOccupiedClassRoom(List<ClassRoom> crs,
			TimeFrame tf) {
		
		List<ClassRoom> crsResult = new Vector<ClassRoom>();
		
		
		for (int i = 0; i < crs.size(); i++) {
			if(! crs.get(i).getOrders().isEmpty()){
				boolean b=false;
				for (int j = 0; j < crs.get(i).getOrders().size(); j++) {
					Order o = crs.get(i).getOrders().get(j);
					for (int k = 0; k < o.getTimeFrames().size(); k++) {
						b= b || tf.isOverlapped((SingleTimeFrame)o.getTimeFrames().get(k));  
						
					}
				}
				if(b)
					crsResult.add(crs.get(i));
			}
		}
		return crsResult;
	}
	
	/**
	 * This method returns all mobile resources that have an order associated
	 * @param mrs
	 * @param totalMrs
	 * @param hmMrs
	 * */
	public HashMap<MobileResource, Integer> findAllOccupiedMobileResource(
			List<MobileResource> mrs, HashMap<MobileResource, Integer> totalMrs,
			HashMap<MobileResource, Integer> hmMrs) {
		
		HashMap<MobileResource,Integer> mrsResult = new HashMap<MobileResource, Integer>();
		
		for (int i = 0; i < mrs.size(); i++) {
			Integer cantMb;
			
			cantMb = totalMrs.get(mrs.get(i)) - hmMrs.get(mrs.get(i));
			mrsResult.put(mrs.get(i), cantMb);
			
		}
		
		
		return mrsResult;
	}

	

}
